package sort;

public class ShellSort {
    public static void shellSort(int[] nums) {
        int len = nums.length;
        int tmp;
        for (int step = len / 2; step >= 1; step /= 2) {
            for (int i = step; i < len; i++) {
                tmp = nums[i];
                int j = i - step;
                while (j >= 0 && nums[j] > tmp) {
                    nums[j + step] = nums[j];
                    j -= step;
                }
                nums[j + step] = tmp;
            }
        }
    }

    public static void main(String[] args) {
        int[] nums = {1, 0, 2, 4, 5, 9, 8, 6, 7, 3};
        Common.printArray(nums);
        shellSort(nums);
        Common.printArray(nums);
    }
}
